package com.lz.order.controller;

import com.lz.order.entity.TbOrderDetail;
import com.lz.order.service.ITbOrderDetailService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lz
 * @since 2024-08-29
 */
@RestController
@RequestMapping("/order")
public class TbOrderDetailController {
    @Resource
    private ITbOrderDetailService orderDetailService;

    @GetMapping("/list")
    public List<TbOrderDetail> getList(){
        List<TbOrderDetail> list = orderDetailService.list();

        return list;
    }

    @PostMapping("/createOrder")
    public TbOrderDetail createOrder(){
        TbOrderDetail tbOrderDetail = new TbOrderDetail();
        tbOrderDetail.setOrderId(System.currentTimeMillis());
        tbOrderDetail.setImage(System.currentTimeMillis()+"");
        tbOrderDetail.setNum(1);
        tbOrderDetail.setPrice(123L);
        orderDetailService.save(tbOrderDetail);

        if (true){
            throw new RuntimeException("测试分布式事务");
        }

        return tbOrderDetail;
    }

}
